# Collect my vim usage for _something_…
# http://www.patrick-wied.at/projects/heatmap-keyboard/
if command -v nvim &> /dev/null; then
    alias vim="nvim -w ~/.vim_keystrokes"
else
    alias vim="vim -w ~/.vim_keystrokes"
fi

# God have mercy on my soul
# alias vim="$HOME/bin/edit"
alias e="$HOME/bin/edit"

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

alias less='less -FirSX'
alias ag='ag --pager "\less -FirSX"'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Colored up cat!
# Easy Insall & Pygments: sudo apt-get install python-pip && sudo pip install Pygments
alias c='pygmentize -O style=monokai -f console256 -g'

# I'm dumb
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias :q='exit'

# I'm <strike>smart</strike> dumb
# alias cd='cd -P'

# be nice
alias please='sudo'

# alias ll="ls -AlFh"
# alias l="ls -AlFh --group-directories-first"
alias l="tree --dirsfirst -ChF -L 1"
alias ll=" tree --dirsfirst --timefmt='%F %H:%M:%S' -CDhFupag -L 1"
alias tlog="tail -f /var/log/syslog"

# View HTTP traffic
alias httpdump="sudo tcpdump -i eth0 -nns 0 -w - | grep -a -E \"Host:|GET\""
alias sniff="sudo ngrep -d 'eth0' -t '^(GET|POST) ' 'tcp and port 80'"
alias localip="/sbin/ifconfig eth0 | awk '/inet addr:.*/ { split(\$2,a,\":\"); print a[2]; }'"

# Recursively delete `.DS_Store` files
alias cleanup="find . -name '*.DS_Store' -type f -ls -delete"

# Shortcuts
alias v="vim"
alias s="svn"
alias plan="$HOME/bin/edit $HOME/.dotfiles/plan"

# File size
alias fs="stat -c \"%s bytes\""

alias sosh=". \"${HOME}/.$(basename $SHELL)rc\""

# IP addresses
alias extip="dig +short myip.opendns.com @resolver1.opendns.com"
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"

# Enhanced WHOIS lookups
alias whois="whois -h whois-servers.net"

# tmux colors:
alias tmux="TERM=screen-256color-bce tmux"
alias tls="tmux list-sessions"
alias ta="tmux attach-session -t"
alias td="tmux kill-session -t"

# mutt colors
alias mutt="TERM=screen-256color-bce mutt"

alias dotfiles="cd ~/.dotfiles"
alias myvimrc="vim ~/.vimrc"

# SVN
alias sst="svn status"
alias sin="svn info"
alias spl="svn pl"
alias spg="svn pg"
alias scom="svn commit"
alias scat="svn cat"
alias sdif="svn diff"
alias srev="svn revert"

# Git
alias gst='git status'
alias gc='git commit -v'
alias ga='git add'
alias gp='git push'
alias gl='git up'
alias gd='git diff'
alias gg='git ack'

# Will return the current branch name
# Usage example: git pull origin $(current_branch)

alias 'hist?'="history | grep -i"

# Dumb osx
if [  "$(uname -s)" = "Darwin" ]; then
    # French Toasting BSD sed
    # alias sed='gsed'

    # Show and hide files in Finder
    alias showhidden="defaults write com.apple.Finder AppleShowAllFiles YES; killall -HUP Finder"
    alias hidehidden="defaults write com.apple.Finder AppleShowAllFiles NO; killall -HUP Finder"

    alias chrome="open -a google\ chrome"
    alias photoshop="open -a '/Applications/Adobe Photoshop CS5/Adobe Photoshop CS5.app'"
    alias f='open -a Finder'

    # Flush Directory Service cache
    alias flushdns="dscacheutil -flushcache"

    alias mountainking="osascript -e 'say \"Dum dum dum dum dum dum dum he he he ho ho ho fa lah lah lah lah lah lah fa lah full hoo hoo hoo\" using \"Cellos\"'"
    alias localip="ipconfig getifaddr en0"
    alias httpdump="sudo tcpdump -i en0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
    alias sniff="sudo ngrep -d 'en0' -t '^(GET|POST) ' 'tcp and port 80'"
fi

# Quick scratch pad
alias vpad="vim +set\ buftype=nofile +startinsert"
alias vundle="vim +PluginInstall +qall"
alias vundleup="vim +PluginUpdate +qall"

# In honor of John
alias govag="cd ~/Development/upsync4/"

if command -v dnsyo > /dev/null 2>&1; then
    alias checkdns=dnsyo
fi

if command -v hiptext > /dev/null 2>&1; then
    alias hiptext="LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib hiptext"
fi

alias ny='telnet miku.acm.uiuc.edu'
alias rr='curl -L http://bit.ly/10hA8iC | bash'
alias sw='telnet towel.blinkenlights.nl'
alias whatisit='curl "http://itsthisforthat.com/api.php?text"'
alias cats="echo && curl -s -k -X GET http://placekitten.com/ | head -n 25 | tail -n 15 && echo"
alias vintage='[ -r "/usr/lib/xscreensaver/apple2" ] && /usr/lib/xscreensaver/apple2 -text -fast -program bash'

if command -v sshecret > /dev/null 2>&1; then
    alias sssh='sshecret'
    alias ssh='sshecret'
    alias scp='scp -S sshecret'
fi
